package com.xd.clap.controller;


import com.xd.clap.entity.FirstAddress;
import com.xd.clap.entity.SecondAddress;
import com.xd.clap.entity.request.AddressParam;
import com.xd.clap.entity.request.MapDetailParam;
import com.xd.clap.entity.request.MapParam;
import com.xd.clap.entity.request.PageParam;
import com.xd.clap.entity.response.Result;
import com.xd.clap.services.FirstAddressService;
import com.xd.clap.services.SecondAddressService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("address")
public class AddressController {
    @Resource
    private FirstAddressService fas;

    @Resource
    private SecondAddressService sas;


    /**
     * 获取一级管辖区信息列表
     */
    @PostMapping("/getFirstAddressList")
    public Result getFirstAddressList() {
        return fas.getFirstAddressList();
    }

    /**
     * 更新或者添加一级管辖区
     */
    @PutMapping("/updateFirstAddress")
    public Result updateFirstAddress(@RequestBody FirstAddress firstAddress) {
        return fas.updateFirstAddress(firstAddress);
    }

    /**
     * 删除一级管辖区
     */
    @DeleteMapping("/delFirstAddress")
    public Result delFirstAddress(FirstAddress firstAddress) {
        return fas.delFirstAddress(firstAddress.getId());
    }
    /**
     * 通过一级辖区ID获取二级管辖区信息列表
     */
    @PostMapping("/getSecondAddressListByFid")
    public Result getSecondAddressListByFid(@RequestBody SecondAddress secondAddress) {
        return sas.getSecondAddressListByFid(secondAddress.getId());
    }

    /**
     * 通过辖区列表获取二级管辖区信息列表
     */
    @PostMapping("/getSecondAddressList")
    public Result getSecondAddressList(@RequestBody MapParam mapParam) {
        return sas.getSecondAddressList(mapParam.getAddressList());
    }


    /**
     * 获取所有辖区信息列表 一级加二级
     */
    @PostMapping("/getAllAddressList")
    public Result getAllAddressList() {
        return fas.getAllAddressList();
    }

    /**
     * 获取所有辖区信息列表 一级包含二级
     */
    @PostMapping("/getAddressList")
    public Result getAddressList() {
        return fas.getAddressList();
    }

    /**
     * 通过关键字查询辖区信息列表
     */
    @PostMapping("/searchAddressList")
    public Result searchAddressList(@RequestBody SecondAddress secondAddress) {
        return fas.searchAddressList(secondAddress.getAddress());
    }

    /**
     * 获取地图标点
     */
    @PostMapping("/getMapIcon")
    public Result getMapIcon(@RequestBody MapParam mapParam) {
        return sas.getMapIcon(mapParam);
    }

    /**
     * 获取意见地图标点信息
     */
    @GetMapping("/getAdviseMapIcon")
    public Result getDetailMapIcon(@RequestParam String greenIcon){
        return sas.getAdviseMapIcon(greenIcon);
    }



    /**
     * 通过二级辖区ID获取辖区信息
     */
    @PostMapping("/getAddressInfo")
    public Result getAddressInfo(@RequestBody SecondAddress secondAddress) {
        return sas.getAddressInfo(secondAddress.getId());
    }

    /**
     * 获取创建点位分页列表
     */
    @PostMapping("/getAddressPage")
    public Result getAddressPage(@RequestBody PageParam pageParam) {
        return sas.getAddressPage(pageParam);
    }

    /**
     * 删除二级点位
     */
    @DeleteMapping("/delAddress")
    public Result delAddress(AddressParam addressParam ){
        return sas.delAddress(addressParam.getId(),addressParam.getSid());
    }

    /**
     * 更新或者添加二级管理员
     */
    @PutMapping("/updateAddress")
    public Result updateAddress(@RequestBody AddressParam addressParam) {
        return sas.updateAddress(addressParam);
    }
}
